using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.PlayerLoop;

public class Golem : EnemyController
{
    [Header("Skill")]
    public float kickForce;
    public GameObject rockPrefeb;
    public Transform handPos;


    public AudioSource AudioSource;
    public AudioClip kinght;
    
    
    public void KickOff()
    {
        if (attackTarget != null && transform.IsFacingTarget(attackTarget.transform))
        {
            var direction = attackTarget.transform.position - transform.position;
            direction.Normalize();

            attackTarget.GetComponent<NavMeshAgent>().isStopped = true;
            attackTarget.GetComponent<NavMeshAgent>().velocity = direction * kickForce;
            attackTarget.GetComponent<Animator>().SetTrigger("Dazzy");
            var targetStats = attackTarget.GetComponent<CharacterStats>();
            targetStats.TakeDamage(characterStats, targetStats);
        }
    }
   
    public void ThrowRock()
    {
        if (attackTarget != null)
        {
            var rock=Instantiate(rockPrefeb, handPos.position, Quaternion.identity);
            rock.GetComponent<Rock>().target = attackTarget;
            AudioSource.Play();
        }
    }

    public override void Update()
    {
        base.Update();
        ChangeView();
    }

    public void ChangeView()
    {
        if (enemyStates == EnemyStates.DIE)
        {
            GameManager.Instance.freeLookCamera.m_Orbits[0].m_Height = 10;
            GameManager.Instance.freeLookCamera.m_Orbits[0].m_Radius = 8;
            GameManager.Instance.freeLookCamera.m_YAxis.Value = 0;
            GameManager.Instance.freeLookCamera.m_LookAt = GameManager.Instance.playerStats.transform;
            AudioManager.Instance.AudioSource.Pause();
            AudioManager.Instance.AudioSource.clip = kinght;
            AudioManager.Instance.AudioSource.Play();
        }
    }
}
